<template>
    <div>
        <van-row style="margin-top: 1rem;"> 
            <van-col span="2" >
                <van-icon name="arrow-left" @click="exit" />
            </van-col>
            
        </van-row>
        <van-row style="margin-bottom: 3rem;">
            <van-col span="6">
                &nbsp;
            </van-col>
            <van-col span="12">
                注册用户
            </van-col>
            <van-col span="6">
                &nbsp;
            </van-col>
        </van-row>
        <van-row>
            <van-col span="24">
                <van-form @submit="onSubmit">
                    <van-field
                        v-model="username"
                        name="username"
                        label="账号"
                        placeholder="账号"
                        :rules="[{ required: true, message: '请填写账号' }]"
             
                    />
                    <van-field
                        v-model="password"
                        type="password"
                        name="password"
                        label="密码"
                        placeholder="密码"
                        :rules="[{ required: true, message: '请填写密码' }]"
                    />

                    <div style="margin: 16px;">
                        <van-button round block type="info" native-type="submit">提交</van-button>
                    </div>
                    </van-form>
            </van-col>
        </van-row>
    </div>
</template>

<script>
    import { Toast } from 'vant';
    import {registUser} from '@/api/index'
    export default {
        data() {
            return {
                username: '',
                password: '',
            };
  },
  methods: {
    onSubmit(values) {
            registUser(values).then(res=>{
                if(res.data.status){
                    Toast("注册成功")
                    this.$router.push('/')
                }
                else 
                    Toast("注册失败")
            })

        
        
    },
    exit(){
        this.$router.push('/my')
    },
    // setUserName(){
    //     this.username=localStorage.getItem('username')
    // }
  },
  mounted(){
    // this.setUserName()
  }
};
</script>